package mo.leetcode_hot;

import java.util.ArrayList;
import java.util.List;

public class L78 {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> combination = new ArrayList<>();
        dfs(res, combination, 0, nums);
        return res;
    }

    private void dfs(List<List<Integer>> res, List<Integer> combination, int idx, int[] nums) {
        if (idx >= nums.length) {
            res.add(new ArrayList<>(combination));
            return;
        }
        combination.add(nums[idx]);
        dfs(res, combination, idx+1, nums);
        combination.remove(combination.size()-1);
        dfs(res, combination, idx+1, nums);
    }

    public static void main(String[] args) {
        L78 test = new L78();
        System.out.println(test.subsets(new int[]{1, 2, 3}));
    }
}
